(function($){
	$.fn.initial=function(){	
		searchBind();
		updateBind();
	}
	var searchBind=function(){
		$("#btn").on('click',$(this),function(){
		
			step1View();
			step2View();
			step3View();
			step4View();
			step5View();
			step6View();
			step7View();
			step8View();
			
		})
		
	}
	var selectBind=function(){
		$("#year-select").on('change',this,function(){
		step1View();
		step2View();
		step3View();
		step4View();
		step5View();
		step6View();
		step7View();
		step8View();
		})
	}
	var updateBind=function(){
		step1Update();
		step2Update();
		step3Update();
		step4Update();
		step5Update();
		step6Update();
		step7Update();
		step8Update();
	}
	
	var step1Update=function(){
		$('#btn1').on('click',$(this),function(){
			var name1=$("#name1").val();
			var linshigong1=$("#linshigong1").val()||0;
			var jishugong1=$("#jishugong1").val()||0;
			var xiaohao1=$("#xiaohao1").val()||0;
			var data={"id":name1,"linshigong":linshigong1,"jishugong":jishugong1,"xiaohao":xiaohao1,"nianfen":$("#year-select").val()};
		
			$.ajax({
				url:"updateps1",
				type:"post",
				data:$.toJSON(data),
				contentType:"application/json;charset=utf-8",
				success:function(data){
					alert(data["message"]);
					
				},
				error:function(){
					alert("写入数据库失败");
				}
			});
		})
	}
	var step1View=function(){
		$('#name1').val();
		$("#linshigong1").val('');
		$("#jishugong1").val('');
		$("#xiaohao1").val('');
		
		var data={"year":$("#year-select").val()};
		$.ajax({
			url:"getps1",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"][0];
					if (data!=null) {
						$('#name1').val(data['id']);
						$("#linshigong1").val(data['linshigong']);
						$("#jishugong1").val(data['jishugong']);
						$("#xiaohao1").val(data['xiaohao']);
					}					
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的种植数据");
					$('#name1').val();
					$("#linshigong1").val('');
					$("#jishugong1").val('');
					$("#xiaohao1").val('');
				}
			},
		})
	}
	
	var step2Update=function(){
		$('#btn2').on('click',$(this),function(){
			var name2=$("#name2").val();
			var linshigong2=$("#linshigong2").val()||0;
			var jishugong2=$("#jishugong2").val()||0;
			var jiqi1=$("#jiqi1").val()||0;
			var jiqi2=$("#jiqi2").val()||0;
			var jiqi3=$("#jiqi3").val()||0;
			var data={"id":name2,"linshigong":linshigong2,"jishugong":jishugong2,"jiqi1":jiqi1,"jiqi2":jiqi2,"jiqi3":jiqi3,"nianfen":$("#year-select").val()};
			
			$.ajax({
				url:"updateps2",
				type:"post",
				data:$.toJSON(data),
				contentType:"application/json;charset=utf-8",
				success:function(data){
					alert(data["message"]);
			
				},
				error:function(){
					alert("写入数据库失败");
				}
			});
		})
	}
	var step2View=function(){
		$('#name2').val('');
		$("#linshigong2").val('');
		$("#jishugong2").val('');
		$("#jiqi1").val('');
		$("#jiqi2").val('');
		$("#jiqi3").val('');
		var data={"year":$("#year-select").val()};
		var body = $("#body2");
		body.html('');
		$.ajax({
			url:"getps2",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"][0];
					if (data!=null) {
						$('#name2').val(data['id']);
						$("#linshigong2").val(data['linshigong']);
						$("#jishugong2").val(data['jishugong']);
						$("#jiqi1").val(data['jiqi1']);
						$("#jiqi2").val(data['jiqi2']);
						$("#jiqi3").val(data['jiqi3']);
					}		
					
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的犁地数据");
					$('#name2').val('');
					$("#linshigong2").val('');
					$("#jishugong2").val('');
					$("#jiqi1").val('');
					$("#jiqi2").val('');
					$("#jiqi3").val('');
				}
			},
		})
	}
	
	var step3Update=function(){
		$('#btn3').on('click',$(this),function(){
			var name3=$("#name3").val();
			var linshigong3=$("#linshigong3").val()||0;
			var jishugong3=$("#jishugong3").val()||0;
			var xiaohao3=$("#xiaohao3").val()||0;
			var data={"id":name3,"linshigong":linshigong3,"jishugong":jishugong3,"xiaohao":xiaohao3,"nianfen":$("#year-select").val()};

			$.ajax({
				url:"updateps3",
				type:"post",
				data:$.toJSON(data),
				contentType:"application/json;charset=utf-8",
				success:function(data){
					alert(data["message"]);
				
				},
				error:function(){
					alert("写入数据库失败");
				}
			});
		})
	}
	
	var step3View=function(){
		$('#name3').val('');
		$("#linshigong3").val('');
		$("#jishugong3").val('');
		$("#xiaohao3").val('');
		
		var data={"year":$("#year-select").val()};
		var body = $("#body3ByNY");
		body.html('');
		$.ajax({
			url:"getps3",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"][0];
					if (data!=null) {
						$('#name3').val(data['id']);
						$("#linshigong3").val(data['linshigong']);
						$("#jishugong3").val(data['jishugong']);
						$("#xiaohao3").val(data['xiaohao']);
					}
					
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的地膜数据");
					$('#name3').val('');
					$("#linshigong3").val('');
					$("#jishugong3").val('');
					$("#xiaohao3").val('');
				}
			},
		})
	}
	
	var step4Update=function(){
		$('#btn4').on('click',$(this),function(){
			var name4=$("#name4").val();
			var linshigong4=$("#linshigong4").val()||0;
			var jishugong4=$("#jishugong4").val()||0;
			var xiaohao4=$("#xiaohao4").val()||0;
			var data={"id":name4,"linshigong":linshigong4,"jishugong":jishugong4,"xiaohao":xiaohao4,"nianfen":$("#year-select").val()};

			$.ajax({
				url:"updateps4",
				type:"post",
				data:$.toJSON(data),
				contentType:"application/json;charset=utf-8",
				success:function(data){
					alert(data["message"]);
				
				},
				error:function(){
					alert("写入数据库失败");
				}
			});
		})
	}
	var step4View=function(){
		$('#name4').val('');
		$("#linshigong4").val('');
		$("#jishugong4").val('');
		$("#xiaohao4").val('');
		
		var data={"year":$("#year-select").val()};
		var body = $("#body4ByNY");
		body.html('');
		$.ajax({
			url:"getps4",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"][0];
					if (data!=null) {
						$('#name4').val(data['id']);
						$("#linshigong4").val(data['linshigong']);
						$("#jishugong4").val(data['jishugong']);
						$("#xiaohao4").val(data['xiaohao']);
					}
					
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的灌溉数据");
					$('#name4').val('');
					$("#linshigong4").val('');
					$("#jishugong4").val('');
					$("#xiaohao4").val('');
				}
			},
		})
	}
	
	var step5Update=function(){
		$('#btn5').on('click',$(this),function(){
			var name=$("#name5").val();
			var linshigong=$("#linshigong5").val()||0;
			var jishugong=$("#jishugong5").val()||0;
			var yjwjfh=$("#yjwjfh").val()||0;
			var elsgnd=$("#elsgnd").val()||0;
			var ns=$("#ns").val()||0;
			var lsen=$("#lsen").val()||0;
			var lsj=$("#lsj").val()||0;
			var lf=$("#lf").val()||0;
			var yjf=$("#yjf").val()||0;
			var data={"id":name,"linshigong":linshigong,"jishugong":jishugong,"yjwjfh":yjwjfh,"elsgnd":elsgnd,"ns":ns,"lsen":lsen,"lsj":lsj,"lf":lf,"yjf":yjf,"nianfen":$("#year-select").val(),"bianhao":0};
	
			$.ajax({
				url:"updateps5",
				type:"post",
				data:$.toJSON(data),
				contentType:"application/json;charset=utf-8",
				success:function(data){
					alert(data["message"]);
			
				},
				error:function(){
					alert("写入数据库失败");
				}
			});
		})
	}
	var step5View=function(){
		$('#name5').val('');
		$("#linshigong5").val('');
		$("#jishugong5").val('');
		$("#yjwjfh").val('');
		$("#elsgnd").val('');
		$("#ns").val('');
		$("#lsen").val('');
		$("#lsj").val('');
		$("#lf").val('');
		$("#yjf").val('');
		
		var data={"year":$("#year-select").val()};
		var body = $("#body5ByNY");
		body.html('');
		$.ajax({
			url:"getps5",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"][0];
					if (data!=null) {
						$('#name5').val(data['id']);
						$("#linshigong5").val(data['linshigong']);
						$("#jishugong5").val(data['jishugong']);
						$("#yjwjfh").val(data['yjwjfh']);
						$("#elsgnd").val(data['elsgnd']);
						$("#ns").val(data['ns']);
						$("#lsen").val(data['lsen']);
						$("#lsj").val(data['lsj']);
						$("#lf").val(data['lf']);
						$("#yjf").val(data['yjf']);
					}			
			
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的施肥数据");
					$('#name5').val('');
					$("#linshigong5").val('');
					$("#jishugong5").val('');
					$("#yjwjfh").val('');
					$("#elsgnd").val('');
					$("#ns").val('');
					$("#lsen").val('');
					$("#lsj").val('');
					$("#lf").val('');
					$("#yjf").val('');
				}
			},
		})
	}
	
	var step6Update=function(){
		$('#btn6').on('click',$(this),function(){
			var name6=$("#name6").val();
			var linshigong6=$("#linshigong6").val()||0;
			var jishugong6=$("#jishugong6").val()||0;
			var ccj=$("#ccj").val()||0;
			var mcj=$("#mcj").val()||0;
			var data={"id":name6,"linshigong":linshigong6,"jishugong":jishugong6,"ccj":ccj,"mcj":mcj,"nianfen":$("#year-select").val()};

			$.ajax({
				url:"updateps6",
				type:"post",
				data:$.toJSON(data),
				contentType:"application/json;charset=utf-8",
				success:function(data){
					alert(data["message"]);
			
				},
				error:function(){
					alert("写入数据库失败");
				}
			});
		})
	}
	var step6View=function(){
		$('#name6').val('');
		$("#linshigong6").val('');
		$("#jishugong6").val('');
		$("#ccj").val('');
		$("#mcj").val('');
		
		var data={"year":$("#year-select").val()};
		var body = $("#body6");
		body.html('');
		$.ajax({
			url:"getps6",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"][0];
					if (data!=null) {
						$('#name6').val(data['id']);
						$("#linshigong6").val(data['linshigong']);
						$("#jishugong6").val(data['jishugong']);
						$("#ccj").val(data['ccj']);
						$("#mcj").val(data['mcj']);
					}			
					
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的喷药数据");
					$('#name6').val('');
					$("#linshigong6").val('');
					$("#jishugong6").val('');
					$("#ccj").val('');
					$("#mcj").val('');
				}
			},
		})
	}
	
	var step7Update=function(){
		$('#btn7').on('click',$(this),function(){
			var name7=$("#name7").val();
			var linshigong7=$("#linshigong7").val()||0;
			var jishugong7=$("#jishugong7").val()||0;
			var zhugan15=$("#zhugan15").val()||0;
			var zhugan30=$("#zhugan30").val()||0;
			var masheng=$("#masheng").val()||0;
			var data={"id":name7,"linshigong":linshigong7,"jishugong":jishugong7,"zhugan15":zhugan15,"zhugan30":zhugan30,"masheng":masheng,"nianfen":$("#year-select").val(),"bianhao":0};

			$.ajax({
				url:"updateps7",
				type:"post",
				data:$.toJSON(data),
				contentType:"application/json;charset=utf-8",
				success:function(data){
					alert(data["message"]);
		
				},
				error:function(){
					alert("写入数据库失败");
				}
			});
		})
	}
	var step7View=function(){
		$('#name7').val('');
		$("#linshigong7").val('');
		$("#jishugong7").val('');
		$("#zhugan15").val('');
		$("#zhugan30").val('');
		$("#masheng").val('');
		var data={"year":$("#year-select").val()};
		var body = $("#body7");
		body.html('');
		$.ajax({
			url:"getps7",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"][0];
					if (data!=null) {
						$('#name7').val(data['id']);
						$("#linshigong7").val(data['linshigong']);
						$("#jishugong7").val(data['jishugong']);
						$("#zhugan15").val(data['zhugan15']);
						$("#zhugan30").val(data['zhugan30']);
						$("#masheng").val(data['masheng']);
					}			
					
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的搭架数据");
					$('#name7').val('');
					$("#linshigong7").val('');
					$("#jishugong7").val('');
					$("#zhugan15").val('');
					$("#zhugan30").val('');
					$("#masheng").val('');
				}
			},
		})
	}
	
	var step8Update=function(){
		$('#btn8').on('click',$(this),function(){
			var name8=$("#name8").val();
			var linshigong8=$("#linshigong8").val()||0;
			var jishugong8=$("#jishugong8").val()||0;
			var data={"id":name8,"linshigong":linshigong8,"jishugong":jishugong8,"nianfen":$("#year-select").val()};

			$.ajax({
				url:"updateps8",
				type:"post",
				data:$.toJSON(data),
				contentType:"application/json;charset=utf-8",
				success:function(data){
					alert(data["message"]);
					$("#name1").val('');
					$("#linshigong1").val('');
					$("#jishugong1").val('');
					$("#xiaohao1").val('');
				},
				error:function(){
					alert("写入数据库失败");
				}
			});
		})
	}
	var step8View=function(){
		$('#name8').val('');
		$("#linshigong8").val('');
		$("#jishugong8").val('');
		var data={"year":$("#year-select").val()};
		var body = $("#body8");
		body.html('');
		$.ajax({
			url:"getps8",
			type:"post",
			data:$.toJSON(data),
			contentType:"application/json;charset=utf-8",
			success:function(data){
				var message=data["message"];
				if (message=="success") {
					data=data["data"][0];
					if (data!=null) {
						$('#name8').val(data['id']);
						$("#linshigong8").val(data['linshigong']);
						$("#jishugong8").val(data['jishugong']);
					}								
				}
				else {
					alert("未查询到作物"+$("#name").val()+"的采摘数据");
					$('#name8').val('');
					$("#linshigong8").val('');
					$("#jishugong8").val('');
				}
			},
		})
	}
})(jQuery)